package com.nineclock.attendance.controller;

import com.nineclock.attendance.AttendGroupControllerApi;
import com.nineclock.attendance.dto.AttendGroupDTO;
import com.nineclock.attendance.service.AttendanceGroupService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("")
public class AttendanceGroupController implements AttendGroupControllerApi{


    @Autowired
    AttendanceGroupService attendanceGroupService;
    @Override
    @GetMapping("/attendGroup")
    public Result<PageResult<AttendGroupDTO>> queryAttendGroupPage(
            @RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize",required = false, defaultValue = "10") Integer pageSize) {
        PageResult<AttendGroupDTO> pageResult = attendanceGroupService.queryAttendGroupPage(page, pageSize);
        return Result.success(pageResult);
    }

    @Override
    @PostMapping("/attendGroup")
    public Result addAttendGroup(@RequestBody AttendGroupDTO attendGroupDTO) {
        attendanceGroupService.addAttendGroup(attendGroupDTO);

        return Result.success();
    }

    @Override
    @GetMapping("/getAttendGroupByUserId")
    public Result<AttendGroupDTO> getAttendGroupByUserId() {
        AttendGroupDTO attendGroupDTO = attendanceGroupService.getAttendGroupByUserId();
        return Result.success(attendGroupDTO);
    }
}
